console.log("二分查找又称折半查找，优点是比较次数少，查找速度快，平均性能好；其缺点是要求待查表为有序表，且插入删除困难。因此，折半查找方法适用于不经常变动而查找频繁的有序列表。");
let arr = [1,2,3,4,5,6,7,8,9]
let binary = function(find,arr,low,high){
    if(low<high){
        if(arr[low]==find){
            return low;
        }
        if(arr[high]==find){
            return high;
        }
        let center = Math.ceil((low+high)/2);
        if(arr[center]==find){
            return center;
        }else if(arr[center]>find){
            return binary(find,arr,low,center-1);
        }else {
            return binary(find,arr,center+1,high);
        }
    }
}
let index = binary(7,arr,0,arr.length-1);
console.log(index);//6
//Math.ceil向上取整
//Math.floor向下取整
//Math.round四舍五入取整